<!DOCTYPE html>
<html lang="en">
<head><meta name="generator" content="Hexo 3.9.0">
    <meta charset="utf-8">
<meta name="google-site-verification" content="phJt8wJDQkOAcEQmqF8UasrF3CVtKMYLBqYLlWfVIOM">
<title>Operate on Mongodb 3.2 - Liyuliang&#39;s Blog</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">



    <meta name="description" content="Server environment12345$ mongoMongoDB shell version v3.4.10connecting to: mongodb://127.0.0.1:27017MongoDB server version: 3.2.17">
<meta name="keywords" content="Mongodb">
<meta property="og:type" content="article">
<meta property="og:title" content="Operate on Mongodb 3.2">
<meta property="og:url" content="https://liyuliang.cc/2017/03/22/Operate-on-Mongodb-3-2/index.html">
<meta property="og:site_name" content="Liyuliang&#39;s Blog">
<meta property="og:description" content="Server environment12345$ mongoMongoDB shell version v3.4.10connecting to: mongodb://127.0.0.1:27017MongoDB server version: 3.2.17">
<meta property="og:locale" content="en">
<meta property="og:updated_time" content="2021-06-14T14:02:02.295Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Operate on Mongodb 3.2">
<meta name="twitter:description" content="Server environment12345$ mongoMongoDB shell version v3.4.10connecting to: mongodb://127.0.0.1:27017MongoDB server version: 3.2.17">





<link rel="icon" href="/images/header.png">


<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.7.2/css/bulma.css">
<link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/5.4.1/css/all.min.css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Ubuntu:400,600|Source+Code+Pro">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@9.12.0/styles/atom-one-light.css">


    
    
    
    <style>body>.footer,body>.navbar,body>.section{opacity:0}</style>
    

    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/css/lightgallery.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/css/justifiedGallery.min.css">
    

    
    

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.css">


    
    
    
    

<link rel="stylesheet" href="/css/back-to-top.css">


    
    

    
    
    
    

    
    
<link rel="stylesheet" href="/css/progressbar.css">
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

    
    
    

    


<script>
        if (document.domain != "liyuliang.cc") {
            window.location.href = "https://liyuliang.cc";
        }
        if (top.location != self.location) {
           top.location = self.location;
        }

</script>
<link rel="stylesheet" href="/css/style.css">

</head>
<body class="is-2-column">
    <nav class="navbar navbar-main">
    <div class="container">
        <div class="navbar-brand is-flex-center">
            <a class="navbar-item navbar-logo" href="/">
            
                Liyuliang&#39;s Blog
            
            </a>
        </div>
        <div class="navbar-menu">
            
            <div class="navbar-start">
                
                <a class="navbar-item" href="/archives">Archives</a>
                
            </div>
            
            <div class="navbar-end">
                
                    
                    
                    <a class="navbar-item" target="_blank" title="Download on GitHub" href="https://github.com/liyuliang">
                        
                        <i class="fab fa-github"></i>
                        
                    </a>
                    
                
                
                
                <a class="navbar-item search" title="Search" href="javascript:;">
                    <i class="fas fa-search"></i>
                </a>
                
            </div>
        </div>
    </div>
</nav>
    
    <section class="section">
        <div class="container">
            <div class="columns">
                <div class="column is-8-tablet is-8-desktop is-8-widescreen has-order-2 column-main"><div class="card">
    
    <div class="card-content article ">
        
        <div class="level article-meta is-size-7 is-uppercase is-mobile is-overflow-x-auto">
            <div class="level-left">
                <time class="level-item has-text-grey" datetime="2017-03-22T06:00:21.000Z">2017-03-22</time>
                
                
                <span class="level-item has-text-grey">
                    
                    
                    10 minutes read (About 1558 words)
                </span>
                
            </div>
        </div>
        
        <h1 class="title is-size-3 is-size-4-mobile has-text-weight-normal">
            
                Operate on Mongodb 3.2
            
        </h1>
        <div class="content">
            <h3 id="Server-environment"><a href="#Server-environment" class="headerlink" title="Server environment"></a>Server environment</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">$ mongo</span><br><span class="line"></span><br><span class="line">MongoDB shell version v3.4.10</span><br><span class="line">connecting to: mongodb://127.0.0.1:27017</span><br><span class="line">MongoDB server version: 3.2.17</span><br></pre></td></tr></table></figure>

<a id="more"></a>

<h3 id="Insert-Document"><a href="#Insert-Document" class="headerlink" title="Insert Document"></a>Insert Document</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.insert(&#123;&quot;title&quot;:&quot;mongo insert&quot;&#125;)</span><br><span class="line">WriteResult(&#123; &quot;nInserted&quot; : 1 &#125;)</span><br></pre></td></tr></table></figure>

<h3 id="Batch-Insert-Document"><a href="#Batch-Insert-Document" class="headerlink" title="Batch Insert Document"></a>Batch Insert Document</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.insert([&#123;&quot;title&quot;:&quot;mongo batch insert part 1&quot;&#125;,&#123;&quot;title&quot;:&quot;mongo batch insert part 2&quot;&#125;,&#123;&quot;title&quot;:&quot;mongo batch insert part 3&quot;&#125;])</span><br><span class="line">  BulkWriteResult(&#123;</span><br><span class="line">  	&quot;writeErrors&quot; : [ ],</span><br><span class="line">  	&quot;writeConcernErrors&quot; : [ ],</span><br><span class="line">  	&quot;nInserted&quot; : 3,</span><br><span class="line">  	&quot;nUpserted&quot; : 0,</span><br><span class="line">  	&quot;nMatched&quot; : 0,</span><br><span class="line">  	&quot;nModified&quot; : 0,</span><br><span class="line">  	&quot;nRemoved&quot; : 0,</span><br><span class="line">  	&quot;upserted&quot; : [ ]</span><br><span class="line">  &#125;)</span><br><span class="line">&gt; db.blog.find()</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;), &quot;title&quot; : &quot;mongo insert&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa36d4a00059e962af668&quot;), &quot;title&quot; : &quot;mongo batch insert part 1&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa36d4a00059e962af669&quot;), &quot;title&quot; : &quot;mongo batch insert part 2&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa36d4a00059e962af66a&quot;), &quot;title&quot; : &quot;mongo batch insert part 3&quot; &#125;</span><br></pre></td></tr></table></figure>

<p>What about repeat insert?<br>The record {“_id” : ObjectId(“5a1fa36d4a00059e962af668”} is exist, i’m going to insert a repeat id record now.</p>
<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.insert([&#123;&quot;_id&quot; : ObjectId(&quot;5a1fa36d4a00059e962af668&quot;),&quot;title&quot;:&quot;mongo batch insert part 4&quot;&#125;,&#123;&quot;title&quot;:&quot;mongo batch insert part 5&quot;&#125;])</span><br><span class="line">BulkWriteResult(&#123;</span><br><span class="line">	&quot;writeErrors&quot; : [</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;index&quot; : 0,</span><br><span class="line">			&quot;code&quot; : 11000,</span><br><span class="line">			&quot;errmsg&quot; : &quot;E11000 duplicate key error collection: test.blog index: _id_ dup key: &#123; : ObjectId(&apos;5a1fa36d4a00059e962af668&apos;) &#125;&quot;,</span><br><span class="line">			&quot;op&quot; : &#123;</span><br><span class="line">				&quot;_id&quot; : ObjectId(&quot;5a1fa36d4a00059e962af668&quot;),</span><br><span class="line">				&quot;title&quot; : &quot;mongo batch insert part 4&quot;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	],</span><br><span class="line">	&quot;writeConcernErrors&quot; : [ ],</span><br><span class="line">	&quot;nInserted&quot; : 0,</span><br><span class="line">	&quot;nUpserted&quot; : 0,</span><br><span class="line">	&quot;nMatched&quot; : 0,</span><br><span class="line">	&quot;nModified&quot; : 0,</span><br><span class="line">	&quot;nRemoved&quot; : 0,</span><br><span class="line">	&quot;upserted&quot; : [ ]</span><br><span class="line">&#125;)</span><br><span class="line">&gt; db.blog.find()</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;), &quot;title&quot; : &quot;mongo insert&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa36d4a00059e962af668&quot;), &quot;title&quot; : &quot;mongo batch insert part 1&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa36d4a00059e962af669&quot;), &quot;title&quot; : &quot;mongo batch insert part 2&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa36d4a00059e962af66a&quot;), &quot;title&quot; : &quot;mongo batch insert part 3&quot; &#125;</span><br></pre></td></tr></table></figure>

<p>Now we know the operate of batch insert will be break off if there is a duplicate key</p>
<ul>
<li>After mongodb version 3.2, the method batchInsert is deprecated</li>
</ul>
<h3 id="InsertMany"><a href="#InsertMany" class="headerlink" title="InsertMany"></a>InsertMany</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.insertMany([&#123;&quot;title&quot;:&quot;mongo insertMany part 1&quot;&#125;,&#123;&quot;title&quot;:&quot;mongo insertMany part 2&quot;&#125;,&#123;&quot;title&quot;:&quot;mongo insertMany part 3&quot;&#125;])</span><br><span class="line">&#123;</span><br><span class="line">	&quot;acknowledged&quot; : true,</span><br><span class="line">	&quot;insertedIds&quot; : [</span><br><span class="line">		ObjectId(&quot;5a1faab4fb4c8a34cc1a4d7e&quot;),</span><br><span class="line">		ObjectId(&quot;5a1faab4fb4c8a34cc1a4d7f&quot;),</span><br><span class="line">		ObjectId(&quot;5a1faab4fb4c8a34cc1a4d80&quot;)</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br><span class="line">&gt; db.blog.find()</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d73&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 1&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d74&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 2&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d75&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 3&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1faab4fb4c8a34cc1a4d7e&quot;), &quot;title&quot; : &quot;mongo insertMany part 1&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1faab4fb4c8a34cc1a4d7f&quot;), &quot;title&quot; : &quot;mongo insertMany part 2&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1faab4fb4c8a34cc1a4d80&quot;), &quot;title&quot; : &quot;mongo insertMany part 3&quot; &#125;</span><br></pre></td></tr></table></figure>

<h3 id="Bulk-Insert"><a href="#Bulk-Insert" class="headerlink" title="Bulk Insert"></a>Bulk Insert</h3><p>The two basic usage are Unordered Operations和Ordered Operations.</p>
<p>Ordered Operations, mongodb will stop and if one of the writing task list makes some errors when it is writing then other writing tasks wil not be continue.<br>Operations which already done will not be rollback.</p>
<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line">&gt; var bulk = db.blog.initializeOrderedBulkOp();</span><br><span class="line">&gt; bulk.insert(&#123;&quot;title&quot;:&quot;mongo bulk insert - Ordered Operations part 1&quot;&#125;);</span><br><span class="line">&gt; bulk.insert(&#123;&quot;title&quot;:&quot;mongo bulk insert - Ordered Operations part 2&quot;&#125;);</span><br><span class="line">&gt; bulk.insert(&#123;&quot;title&quot;:&quot;mongo bulk insert - Ordered Operations part 3&quot;&#125;);</span><br><span class="line">&gt; bulk.execute()</span><br><span class="line">BulkWriteResult(&#123;</span><br><span class="line">	&quot;writeErrors&quot; : [ ],</span><br><span class="line">	&quot;writeConcernErrors&quot; : [ ],</span><br><span class="line">	&quot;nInserted&quot; : 3,</span><br><span class="line">	&quot;nUpserted&quot; : 0,</span><br><span class="line">	&quot;nMatched&quot; : 0,</span><br><span class="line">	&quot;nModified&quot; : 0,</span><br><span class="line">	&quot;nRemoved&quot; : 0,</span><br><span class="line">	&quot;</span><br><span class="line">&gt; db.blog.find()</span><br><span class="line">...</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d73&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 1&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d74&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 2&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d75&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 3&quot; &#125;</span><br></pre></td></tr></table></figure>

<p>Unordered Operations, it will not be stop if one of the writing task list makes errors then other task will continue their work.So this usage is much faster  </p>
<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">&gt; var bulk = db.blog.initializeUnorderedBulkOp();</span><br><span class="line">&gt; bulk.insert(&#123;&quot;title&quot;:&quot;mongo bulk insert - Unordered Operations part 1&quot;&#125;);</span><br><span class="line">&gt; bulk.insert(&#123;&quot;title&quot;:&quot;mongo bulk insert - Unordered Operations part 2&quot;&#125;);</span><br><span class="line">&gt; bulk.insert(&#123;&quot;title&quot;:&quot;mongo bulk insert - Unordered Operations part 3&quot;&#125;);</span><br><span class="line">&gt; bulk.execute();</span><br><span class="line">BulkWriteResult(&#123;</span><br><span class="line">	&quot;writeErrors&quot; : [ ],</span><br><span class="line">	&quot;writeConcernErrors&quot; : [ ],</span><br><span class="line">	&quot;nInserted&quot; : 3,</span><br><span class="line">	&quot;nUpserted&quot; : 0,</span><br><span class="line">	&quot;nMatched&quot; : 0,</span><br><span class="line">	&quot;nModified&quot; : 0,</span><br><span class="line">	&quot;nRemoved&quot; : 0,</span><br><span class="line">	&quot;upserted&quot; : [ ]</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">&gt; var bulk = db.blog.initializeUnorderedBulkOp();</span><br><span class="line">&gt; bulk.insert(&#123;&quot;title&quot;:&quot;mongo bulk insert - Unordered Operations part 4&quot;&#125;);</span><br><span class="line">&gt; bulk.insert(&#123;&quot;_id&quot; : ObjectId(&quot;5a1fa81efb4c8a34cc1a4d79&quot;),&quot;title&quot;:&quot;mongo bulk insert - Unordered Operations part 5&quot;&#125;);</span><br><span class="line">&gt; bulk.insert(&#123;&quot;title&quot;:&quot;mongo bulk insert - Unordered Operations part 6&quot;&#125;);</span><br><span class="line">&gt; bulk.execute();</span><br><span class="line">2017-03-22T14:43:51.928+0800 E QUERY    [thread1] BulkWriteError: write error at item 1 in bulk operation :</span><br><span class="line">BulkWriteError(&#123;</span><br><span class="line">	&quot;writeErrors&quot; : [</span><br><span class="line">		&#123;</span><br><span class="line">			&quot;index&quot; : 1,</span><br><span class="line">			&quot;code&quot; : 11000,</span><br><span class="line">			&quot;errmsg&quot; : &quot;E11000 duplicate key error collection: test.blog index: _id_ dup key: &#123; : ObjectId(&apos;5a1fa81efb4c8a34cc1a4d79&apos;) &#125;&quot;,</span><br><span class="line">			&quot;op&quot; : &#123;</span><br><span class="line">				&quot;_id&quot; : ObjectId(&quot;5a1fa81efb4c8a34cc1a4d79&quot;),</span><br><span class="line">				&quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 5&quot;</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">	],</span><br><span class="line">	&quot;writeConcernErrors&quot; : [ ],</span><br><span class="line">	&quot;nInserted&quot; : 2,</span><br><span class="line">	&quot;nUpserted&quot; : 0,</span><br><span class="line">	&quot;nMatched&quot; : 0,</span><br><span class="line">	&quot;nModified&quot; : 0,</span><br><span class="line">	&quot;nRemoved&quot; : 0,</span><br><span class="line">	&quot;upserted&quot; : [ ]</span><br><span class="line">&#125;)</span><br><span class="line"></span><br><span class="line">&gt; db.blog.find()</span><br><span class="line">...</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa81efb4c8a34cc1a4d79&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 1&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa81efb4c8a34cc1a4d7a&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 2&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa81efb4c8a34cc1a4d7b&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 3&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa8a7fb4c8a34cc1a4d7c&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 4&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa8a7fb4c8a34cc1a4d7d&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 6&quot; &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>The max document size must less than 16MB.</li>
</ul>
<h3 id="Update"><a href="#Update" class="headerlink" title="Update"></a>Update</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.update(&#123;&quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;)&#125;,&#123;&quot;$set&quot;:&#123;&quot;subTitle&quot;:&quot;mongo update&quot;,&quot;tags&quot;:[&quot;mongo&quot;,&quot;mongo3.2&quot;,&quot;mongo update&quot;]&#125;&#125;)</span><br><span class="line">WriteResult(&#123; &quot;nMatched&quot; : 1, &quot;nUpserted&quot; : 0, &quot;nModified&quot; : 1 &#125;)</span><br><span class="line">&gt; db.blog.findOne(&#123;&quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;)&#125;)</span><br><span class="line">&#123;</span><br><span class="line">	    &quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;),</span><br><span class="line">	    &quot;title&quot; : &quot;mongo insert&quot;,</span><br><span class="line">		&quot;subTitle&quot; : &quot;mongo update&quot;,</span><br><span class="line">    	&quot;tags&quot; : [</span><br><span class="line">    		&quot;mongo&quot;,</span><br><span class="line">    		&quot;mongo3.2&quot;,</span><br><span class="line">    		&quot;mongo update&quot;</span><br><span class="line">    	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Append-Update"><a href="#Append-Update" class="headerlink" title="Append Update"></a>Append Update</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.update(&#123;&quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;)&#125;,&#123;&quot;$push&quot;:&#123;&quot;comments&quot;:[&#123;&quot;name&quot;:&quot;liang&quot;,&quot;content&quot;:&quot;wow~ lucky!&quot;&#125;,&#123;&quot;name&quot;:&quot;Jack&quot;,&quot;content&quot;:&quot;hihi~~&quot;&#125;]&#125;&#125;)</span><br><span class="line">WriteResult(&#123; &quot;nMatched&quot; : 1, &quot;nUpserted&quot; : 0, &quot;nModified&quot; : 1 &#125;)</span><br><span class="line">&gt; db.blog.findOne(&#123;&quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;)&#125;)</span><br><span class="line">&#123;</span><br><span class="line">	&quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;),</span><br><span class="line">	&quot;title&quot; : &quot;mongo insert&quot;,</span><br><span class="line">	&quot;subTitle&quot; : &quot;mongo update&quot;,</span><br><span class="line">	&quot;tags&quot; : [</span><br><span class="line">		&quot;mongo&quot;,</span><br><span class="line">		&quot;mongo3.2&quot;,</span><br><span class="line">		&quot;mongo update&quot;</span><br><span class="line">	],</span><br><span class="line">	&quot;comments&quot; : [</span><br><span class="line">		[</span><br><span class="line">			&#123;</span><br><span class="line">				&quot;name&quot; : &quot;liang&quot;,</span><br><span class="line">				&quot;content&quot; : &quot;wow~ lucky!&quot;</span><br><span class="line">			&#125;,</span><br><span class="line">			&#123;</span><br><span class="line">				&quot;name&quot; : &quot;Jack&quot;,</span><br><span class="line">				&quot;content&quot; : &quot;hihi~~&quot;</span><br><span class="line">			&#125;</span><br><span class="line">		]</span><br><span class="line">	]</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Update-record-does-not-exist"><a href="#Update-record-does-not-exist" class="headerlink" title="Update record does not exist"></a>Update record does not exist</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.update(&#123;&quot;_id&quot; : &quot;notexistid&quot;&#125;,&#123;&quot;$set&quot;:&#123;&quot;content&quot;:&quot;not exist record&quot;&#125;&#125;,true)</span><br><span class="line">WriteResult(&#123; &quot;nMatched&quot; : 0, &quot;nUpserted&quot; : 0, &quot;nModified&quot; : 0 &#125;)</span><br></pre></td></tr></table></figure>

<h3 id="Upsert"><a href="#Upsert" class="headerlink" title="Upsert"></a>Upsert</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.update(&#123;&quot;_id&quot; : &quot;notexistid&quot;&#125;,&#123;&quot;$set&quot;:&#123;&quot;content&quot;:&quot;not exist record&quot;&#125;&#125;,true)</span><br><span class="line">WriteResult(&#123; &quot;nMatched&quot; : 0, &quot;nUpserted&quot; : 1, &quot;nModified&quot; : 0, &quot;_id&quot; : &quot;notexistid&quot; &#125;)</span><br><span class="line">&gt; db.blog.find()</span><br><span class="line">...</span><br><span class="line">&#123; &quot;_id&quot; : &quot;notexistid&quot;, &quot;content&quot; : &quot;not exist record&quot; &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>The third parameter in update method indicates that if the record does not exist, the operation will become an insert operation</li>
</ul>
<h3 id="Multi-Update"><a href="#Multi-Update" class="headerlink" title="Multi Update"></a>Multi Update</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.update(&#123;&quot;title&quot;:&#123;&quot;$ne&quot;:&quot;&quot;&#125;&#125;,&#123;&quot;$set&quot;:&#123;&quot;author&quot;:&quot;liang&quot;&#125;&#125;,false,true)</span><br><span class="line">WriteResult(&#123; &quot;nMatched&quot; : 13, &quot;nUpserted&quot; : 0, &quot;nModified&quot; : 13 &#125;)</span><br><span class="line">&gt; db.blog.find()</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d73&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 1&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d74&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 2&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa79efb4c8a34cc1a4d75&quot;), &quot;title&quot; : &quot;mongo bulk insert - Ordered Operations part 3&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa81efb4c8a34cc1a4d79&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 1&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa81efb4c8a34cc1a4d7a&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 2&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa81efb4c8a34cc1a4d7b&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 3&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa8a7fb4c8a34cc1a4d7c&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 4&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1fa8a7fb4c8a34cc1a4d7d&quot;), &quot;title&quot; : &quot;mongo bulk insert - Unordered Operations part 6&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1faab4fb4c8a34cc1a4d7e&quot;), &quot;title&quot; : &quot;mongo insertMany part 1&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1faab4fb4c8a34cc1a4d7f&quot;), &quot;title&quot; : &quot;mongo insertMany part 2&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a1faab4fb4c8a34cc1a4d80&quot;), &quot;title&quot; : &quot;mongo insertMany part 3&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;), &quot;title&quot; : &quot;mongo insert&quot;, &quot;subTitle&quot; : &quot;mongo update&quot;, &quot;tags&quot; : [ &quot;mongo&quot;, &quot;mongo3.2&quot;, &quot;mongo update&quot; ], &quot;comments&quot; : [ [ &#123; &quot;name&quot; : &quot;liang&quot;, &quot;content&quot; : &quot;wow~ lucky!&quot; &#125;, &#123; &quot;name&quot; : &quot;Jack&quot;, &quot;content&quot; : &quot;hihi~~&quot; &#125; ] ], &quot;author&quot; : &quot;liang&quot; &#125;</span><br><span class="line">&#123; &quot;_id&quot; : &quot;notexistid&quot;, &quot;content&quot; : &quot;not exist record&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>The fourth parameter in update method indicates that all matching documents will be updated</li>
</ul>
<h3 id="findAndModify"><a href="#findAndModify" class="headerlink" title="findAndModify"></a>findAndModify</h3><p>Note that the findAndModify operation is atomic !</p>
<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.runCommand(&#123;&quot;findAndModify&quot;:&quot;blog&quot;</span><br><span class="line">... ,&quot;query&quot;:&#123;&quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;)&#125;,</span><br><span class="line">... &quot;sort&quot;:&#123;&quot;_id&quot;:&quot;-1&quot;&#125;,</span><br><span class="line">... &quot;update&quot;:&#123;&quot;$set&quot;:&#123;&quot;price&quot;:100&#125;&#125;</span><br><span class="line">... &#125;)</span><br><span class="line">&#123;</span><br><span class="line">	&quot;lastErrorObject&quot; : &#123;</span><br><span class="line">		&quot;updatedExisting&quot; : true,</span><br><span class="line">		&quot;n&quot; : 1</span><br><span class="line">	&#125;,</span><br><span class="line">	&quot;value&quot; : &#123;</span><br><span class="line">		&quot;_id&quot; : ObjectId(&quot;5a202c00fb4c8a34cc1a4d81&quot;),</span><br><span class="line">		&quot;title&quot; : &quot;mongo insert&quot;,</span><br><span class="line">		&quot;subTitle&quot; : &quot;mongo update&quot;,</span><br><span class="line">		&quot;tags&quot; : [</span><br><span class="line">			&quot;mongo&quot;,</span><br><span class="line">			&quot;mongo3.2&quot;,</span><br><span class="line">			&quot;mongo update&quot;</span><br><span class="line">		],</span><br><span class="line">		&quot;comments&quot; : [</span><br><span class="line">			[</span><br><span class="line">				&#123;</span><br><span class="line">					&quot;name&quot; : &quot;liang&quot;,</span><br><span class="line">					&quot;content&quot; : &quot;wow~ lucky!&quot;</span><br><span class="line">				&#125;,</span><br><span class="line">				&#123;</span><br><span class="line">					&quot;name&quot; : &quot;Jack&quot;,</span><br><span class="line">					&quot;content&quot; : &quot;hihi~~&quot;</span><br><span class="line">				&#125;</span><br><span class="line">			]</span><br><span class="line">		],</span><br><span class="line">		&quot;author&quot; : &quot;liang&quot;</span><br><span class="line">	&#125;,</span><br><span class="line">	&quot;ok&quot; : 1</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="Find"><a href="#Find" class="headerlink" title="Find"></a>Find</h3><p>Insert a record.</p>
<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.insert(&#123;&quot;title&quot;:&quot;mongo find&quot;,&quot;author&quot;:&quot;liang&quot;,&quot;language&quot;:&quot;english&quot;,&quot;price&quot;:&#123;&quot;max&quot;:99,&quot;min&quot;:60&#125;&#125;)</span><br><span class="line">WriteResult(&#123; &quot;nInserted&quot; : 1 &#125;)</span><br></pre></td></tr></table></figure>

<figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">&gt; db.blog.find(&#123;&quot;price.max&quot;:&#123;&quot;$lte&quot;:99,&quot;$gte&quot;:60&#125;,&quot;author&quot;:&quot;liang&quot;&#125;,&#123;&quot;title&quot;:1,&quot;author&quot;:1,&quot;_id&quot;:0&#125;)</span><br><span class="line">&#123; &quot;title&quot; : &quot;mongo find&quot;, &quot;author&quot; : &quot;liang&quot; &#125;</span><br></pre></td></tr></table></figure>

<p>The first param is query condition, the second param is query result(it will not return if this value is zero)</p>
<h3 id="Cursor"><a href="#Cursor" class="headerlink" title="Cursor"></a>Cursor</h3><figure class="highlight plain hljs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">&gt; for(i=0;i&lt;100;i++)&#123;</span><br><span class="line">... db.blog.insert(&#123;&quot;author&quot;:&quot;liang&quot;,&quot;title&quot;:&quot;cursor insert &quot;+i&#125;);</span><br><span class="line">... &#125;</span><br><span class="line">WriteResult(&#123; &quot;nInserted&quot; : 1 &#125;)</span><br><span class="line"></span><br><span class="line">&gt; var cursor = db.blog.find();</span><br><span class="line">&gt; while(cursor.hasNext())&#123;</span><br><span class="line">... obj = cursor.next();</span><br><span class="line">... &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li>If the number of query result is huge, cursor will meet a repeat document<br>If document becomes bigger when data from database increased after business process, this document ‘s memory address will be reassign.<br>When the cursor is moved to right, it will re-meet the same document with a new address again</li>
</ul>

        </div>
        
        <div class="level is-size-7 is-uppercase">
            <div class="level-start">
                <div class="level-item">
                    <span class="is-size-6 has-text-grey has-mr-7">#</span>
                    <a class="has-link-grey -link" href="/tags/Mongodb/">Mongodb</a>
                </div>
            </div>
        </div>
        
        
        
            <p class="is-size-7">
    <b>
    Thank you for reading.<br>
    This post is copyrighted by <a href="https://liyuliang.cc">Liyuliang’s Blog.</a><br>
    If reproduced, please indicate the source: <a href="https://liyuliang.cc">Liyuliang’s Blog</a><br>
    This blog uses <a target="_blank" rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons Attribution-NonCommercial-Share-Sharing 4.0 International License Agreement </a> to license.<br>
    </b>
    <hr>
</p>
        
        
    </div>
</div>



<div class="card">
    <div class="card-content">
        <h3 class="menu-label has-text-centered">Like this article? Support the author with</h3>
        <div class="buttons is-centered">
            
                
<a class="button is-info donate">
    <span class="icon is-small">
        <i class="fab fa-alipay"></i>
    </span>
    <span>Alipay</span>
    <div class="qrcode"><img src="/images/alipay.jpeg" alt="Alipay"></div>
</a>

                
                
<a class="button is-success donate">
    <span class="icon is-small">
        <i class="fab fa-weixin"></i>
    </span>
    <span>Wechat</span>
    <div class="qrcode"><img src="/images/wxpay.jpeg" alt="Wechat"></div>
</a>

                
                <!-- Visit https://www.paypal.com/donate/buttons/ to get your donate button -->

<a class="button is-warning donate" onclick="document.getElementById(&#39;paypal-donate-form&#39;).submit()">
    <span class="icon is-small">
        <i class="fab fa-paypal"></i>
    </span>
    <span>Paypal</span>
</a>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank" id="paypal-donate-form">
    <input type="hidden" name="cmd" value="_donations">
    <input type="hidden" name="business" value="D7RUA6PUE8GM2">
    <input type="hidden" name="currency_code" value="USD">
</form>

                
        </div>
    </div>
</div>



<div class="card card-transparent">
    <div class="level post-navigation is-flex-wrap is-mobile">
        
        <div class="level-start">
            <a class="level level-item has-link-grey  article-nav-prev" href="/2017/03/22/How-Mongodb-Build-The-Replica-Set/">
                <i class="level-item fas fa-chevron-left"></i>
                <span class="level-item">How Mongodb Build The Replica Set</span>
            </a>
        </div>
        
        
        <div class="level-end">
            <a class="level level-item has-link-grey  article-nav-next" href="/2017/03/21/How-to-implement-login-form-by-Symfony3/">
                <span class="level-item">How to implement login form by Symfony3</span>
                <i class="level-item fas fa-chevron-right"></i>
            </a>
        </div>
        
    </div>
</div>


</div>
                
                




<div class="column is-4-tablet is-4-desktop is-4-widescreen  has-order-3 column-right is-sticky">
    
        <div class="card widget">
    <div class="card-content">
        <div class="menu">
        <h3 class="menu-label">
            Archives
        </h3>
        <ul class="menu-list">
        
        <li>
            <a class="level is-marginless" href="/archives/2018/06/">
                <span class="level-start">
                    <span class="level-item">June 2018</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">3</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2018/05/">
                <span class="level-start">
                    <span class="level-item">May 2018</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2018/04/">
                <span class="level-start">
                    <span class="level-item">April 2018</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">1</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2018/03/">
                <span class="level-start">
                    <span class="level-item">March 2018</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">3</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2018/02/">
                <span class="level-start">
                    <span class="level-item">February 2018</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">3</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2018/01/">
                <span class="level-start">
                    <span class="level-item">January 2018</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">6</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/12/">
                <span class="level-start">
                    <span class="level-item">December 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">3</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/11/">
                <span class="level-start">
                    <span class="level-item">November 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">2</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/10/">
                <span class="level-start">
                    <span class="level-item">October 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">5</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/09/">
                <span class="level-start">
                    <span class="level-item">September 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">8</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/08/">
                <span class="level-start">
                    <span class="level-item">August 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">10</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/07/">
                <span class="level-start">
                    <span class="level-item">July 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">3</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/06/">
                <span class="level-start">
                    <span class="level-item">June 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">6</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/05/">
                <span class="level-start">
                    <span class="level-item">May 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">9</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/04/">
                <span class="level-start">
                    <span class="level-item">April 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">7</span>
                </span>
            </a>
        </li>
        
        <li>
            <a class="level is-marginless" href="/archives/2017/03/">
                <span class="level-start">
                    <span class="level-item">March 2017</span>
                </span>
                <span class="level-end">
                    <span class="level-item tag">9</span>
                </span>
            </a>
        </li>
        
        </ul>
        </div>
    </div>
</div>
    
        
<div class="card widget">
    <div class="card-content">
        <h3 class="menu-label">
            Tag Cloud
        </h3>
        <a href="/tags/Alipay/" style="font-size: 10px;">Alipay</a> <a href="/tags/Apache/" style="font-size: 12px;">Apache</a> <a href="/tags/Baidu/" style="font-size: 10px;">Baidu</a> <a href="/tags/Canal/" style="font-size: 10px;">Canal</a> <a href="/tags/Centos/" style="font-size: 10px;">Centos</a> <a href="/tags/CloudDisk/" style="font-size: 10px;">CloudDisk</a> <a href="/tags/Daemon/" style="font-size: 11px;">Daemon</a> <a href="/tags/Elasticsearch/" style="font-size: 13px;">Elasticsearch</a> <a href="/tags/Filebeat/" style="font-size: 11px;">Filebeat</a> <a href="/tags/Glide/" style="font-size: 10px;">Glide</a> <a href="/tags/Iterm/" style="font-size: 10px;">Iterm</a> <a href="/tags/JQuery/" style="font-size: 10px;">JQuery</a> <a href="/tags/Keepalived/" style="font-size: 10px;">Keepalived</a> <a href="/tags/Kibana/" style="font-size: 11px;">Kibana</a> <a href="/tags/Linux/" style="font-size: 10px;">Linux</a> <a href="/tags/Login/" style="font-size: 10px;">Login</a> <a href="/tags/Logstash/" style="font-size: 11px;">Logstash</a> <a href="/tags/Mac/" style="font-size: 14px;">Mac</a> <a href="/tags/Mongodb/" style="font-size: 11px;">Mongodb</a> <a href="/tags/Mycat/" style="font-size: 10px;">Mycat</a> <a href="/tags/Mysql/" style="font-size: 19px;">Mysql</a> <a href="/tags/NFS/" style="font-size: 10px;">NFS</a> <a href="/tags/Nginx/" style="font-size: 10px;">Nginx</a> <a href="/tags/Nodejs/" style="font-size: 10px;">Nodejs</a> <a href="/tags/PHP/" style="font-size: 18px;">PHP</a> <a href="/tags/Pagespeed/" style="font-size: 10px;">Pagespeed</a> <a href="/tags/Partition/" style="font-size: 10px;">Partition</a> <a href="/tags/Redis/" style="font-size: 12px;">Redis</a> <a href="/tags/Replica/" style="font-size: 10px;">Replica</a> <a href="/tags/Security/" style="font-size: 10px;">Security</a> <a href="/tags/Slave/" style="font-size: 13px;">Slave</a> <a href="/tags/SlowLog/" style="font-size: 11px;">SlowLog</a> <a href="/tags/Symfony/" style="font-size: 15px;">Symfony</a> <a href="/tags/TCP/" style="font-size: 10px;">TCP</a> <a href="/tags/Twig/" style="font-size: 11px;">Twig</a> <a href="/tags/Ubuntu/" style="font-size: 20px;">Ubuntu</a> <a href="/tags/Varnish/" style="font-size: 10px;">Varnish</a> <a href="/tags/Vim/" style="font-size: 10px;">Vim</a> <a href="/tags/Virtualbox/" style="font-size: 10px;">Virtualbox</a> <a href="/tags/Wordpress/" style="font-size: 11px;">Wordpress</a> <a href="/tags/auth/" style="font-size: 11px;">auth</a> <a href="/tags/backup/" style="font-size: 10px;">backup</a> <a href="/tags/beanstalkd/" style="font-size: 10px;">beanstalkd</a> <a href="/tags/binlog/" style="font-size: 10px;">binlog</a> <a href="/tags/blog/" style="font-size: 10px;">blog</a> <a href="/tags/brew/" style="font-size: 11px;">brew</a> <a href="/tags/composer/" style="font-size: 10px;">composer</a> <a href="/tags/cookie/" style="font-size: 10px;">cookie</a> <a href="/tags/css/" style="font-size: 10px;">css</a> <a href="/tags/dante/" style="font-size: 10px;">dante</a> <a href="/tags/docker/" style="font-size: 12px;">docker</a> <a href="/tags/domain/" style="font-size: 11px;">domain</a> <a href="/tags/download/" style="font-size: 10px;">download</a> <a href="/tags/file/" style="font-size: 10px;">file</a> <a href="/tags/fork/" style="font-size: 10px;">fork</a> <a href="/tags/git/" style="font-size: 11px;">git</a> <a href="/tags/github/" style="font-size: 10px;">github</a> <a href="/tags/gitlab/" style="font-size: 10px;">gitlab</a> <a href="/tags/golang/" style="font-size: 17px;">golang</a> <a href="/tags/homestead/" style="font-size: 10px;">homestead</a> <a href="/tags/iptable/" style="font-size: 11px;">iptable</a> <a href="/tags/laravel/" style="font-size: 10px;">laravel</a> <a href="/tags/log/" style="font-size: 10px;">log</a> <a href="/tags/nginx/" style="font-size: 16px;">nginx</a> <a href="/tags/proxy/" style="font-size: 11px;">proxy</a> <a href="/tags/redis-cluster/" style="font-size: 10px;">redis-cluster</a> <a href="/tags/redis-sentinel/" style="font-size: 10px;">redis-sentinel</a> <a href="/tags/sock5/" style="font-size: 10px;">sock5</a> <a href="/tags/supervisor/" style="font-size: 10px;">supervisor</a> <a href="/tags/sync/" style="font-size: 10px;">sync</a> <a href="/tags/tips/" style="font-size: 11px;">tips</a> <a href="/tags/tmux/" style="font-size: 10px;">tmux</a> <a href="/tags/usb/" style="font-size: 10px;">usb</a> <a href="/tags/vagrant/" style="font-size: 10px;">vagrant</a> <a href="/tags/web/" style="font-size: 10px;">web</a>
    </div>
</div>

    
        


    
    
</div>

            </div>
        </div>
    </section>
    <footer class="footer">
    <div class="container">
        <div class="level">
            <div class="level-start has-text-centered-mobile">
                <a class="footer-logo is-block has-mb-6" href="/">
                
                    Liyuliang&#39;s Blog
                
                </a>

                <p class="is-size-7">
                    <a href="/copyright" target="_blank">Copyright</a>
                    &copy; 2022 Liyuliang&nbsp;

		    <a target="_blank" href="https://beian.miit.gov.cn">粤ICP备18120141号</a>
                </p>
            </div>
            <div class="level-end">
            
                <div class="field has-addons is-flex-center-mobile has-mt-5-mobile is-flex-wrap is-flex-middle">
                
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" title="Creative Commons" href="https://creativecommons.org/">
                        
                        <i class="fab fa-creative-commons"></i>
                        
                    </a>
                </p>
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" title="Attribution 4.0 International" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">
                        
                        <i class="fab fa-creative-commons-by"></i>
                        
                    </a>
                </p>
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" title="Download on GitHub" href="https://github.com/liyuliang">
                        
                        <i class="fab fa-github"></i>
                        
                    </a>
                </p>
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" title="SiteMap for Google" href="https://liyuliang.cc/sitemap.xml">
                        
                        <i class="fab fa-google"></i>
                        
                    </a>
                </p>
                
                <p class="control">
                    <a class="button is-white is-large" target="_blank" title="SiteMap for Baidu" href="https://liyuliang.cc/baidusitemap.xml">
                        
                        <i class="fab fa-bimobject"></i>
                        
                    </a>
                </p>
                
                </div>
            
            </div>
        </div>
    </div>
</footer>

    <script src="https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/moment@2.22.2/min/moment-with-locales.min.js"></script>
<script>moment.locale("en");</script>


    
    
    
    <script src="/js/animation.js"></script>
    

    
    
    
    <script src="https://cdn.jsdelivr.net/npm/lightgallery@1.6.8/dist/js/lightgallery.min.js" defer></script>
    <script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js" defer></script>
    <script src="/js/gallery.js" defer></script>
    

    
    

<div id="outdated">
    <h6>Your browser is out-of-date!</h6>
    <p>Update your browser to view this website correctly. <a id="btnUpdateBrowser" href="http://outdatedbrowser.com/">Update
            my browser now </a></p>
    <p class="last"><a href="#" id="btnCloseUpdateBrowser" title="Close">&times;</a></p>
</div>
<script src="https://cdn.jsdelivr.net/npm/outdatedbrowser@1.1.5/outdatedbrowser/outdatedbrowser.min.js" defer></script>
<script>
    document.addEventListener("DOMContentLoaded", function () {
        outdatedBrowser({
            bgColor: '#f25648',
            color: '#ffffff',
            lowerThan: 'flex'
        });
    });
</script>


    
    
<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.5/unpacked/MathJax.js?config=TeX-MML-AM_CHTML" defer></script>
<script>
document.addEventListener('DOMContentLoaded', function () {
    MathJax.Hub.Config({
        'HTML-CSS': {matchFontHeight: false},
        SVG: {matchFontHeight: false},
        CommonHTML: {matchFontHeight: false}
    });
});
</script>

    
    

<a id="back-to-top" title="Back to Top" href="javascript:;">
    <i class="fas fa-chevron-up"></i>
</a>
<script src="/js/back-to-top.js" defer></script>


    
    

    
    
    
    

    
    
    
    
    
    <script src="https://cdn.jsdelivr.net/npm/clipboard@2.0.4/dist/clipboard.min.js" defer></script>
    <script src="/js/clipboard.js" defer></script>
    

    


<script src="/js/main.js" defer></script>

    
    <div class="searchbox ins-search">
    <div class="searchbox-container ins-search-container">
        <div class="searchbox-input-wrapper">
            <input type="text" class="searchbox-input ins-search-input" placeholder="Type something...">
            <span class="searchbox-close ins-close ins-selectable"><i class="fa fa-times-circle"></i></span>
        </div>
        <div class="searchbox-result-wrapper ins-section-wrapper">
            <div class="ins-section-container"></div>
        </div>
    </div>
</div>
<script>
    (function (window) {
        var INSIGHT_CONFIG = {
            TRANSLATION: {
                POSTS: 'Posts',
                PAGES: 'Pages',
                CATEGORIES: 'Categories',
                TAGS: 'Tags',
                UNTITLED: '(Untitled)',
            },
            CONTENT_URL: '/content.json',
        };
        window.INSIGHT_CONFIG = INSIGHT_CONFIG;
    })(window);
</script>
<script src="/js/insight.js" defer></script>
<link rel="stylesheet" href="/css/search.css">
<link rel="stylesheet" href="/css/insight.css">
    
</body>
</html>